var xmlHttpRequest;
function createXMLHttpRequest()
{
    if (window.XMLHttpRequest) //非IE浏览器
    {
        xmlHttpRequest = new XMLHttpRequest();
    }
    else if (window.ActiveObject)//IE6以上版本的IE浏览器
    {
        xmlHttpRequest = new ActiveObject("Msxml2.XMLHTTP");
    }
    else //IE6及以下版本IE浏览器
    {
        xmlHttpRequest = new ActiveObject("Microsoft.XMLHTTP");
    }
}

function usernameIsExist() {
    var xhr;
    var username = document.getElementById('username').value;
    xhr = new XMLHttpRequest();
    xhr.onreadystatechange = processResponse;
    xhr.open("GET","usernameIsExistServlet?username=" + username,true);
    xhr.send(null);
}

function processResponse() {
    if (xmlHttpRequest.readyState == 4) {
        if (xmlHttpRequest.status == 200) {
            var tips = xhr.getElementById("usernameMsg");
            var responseInfo = xhr.responseText;

            if (responseInfo == "Exist") {
                tips.innerHTML = "<font color='red'>用户名已存在</font>";
            } else {
                tips.innerHTML = "<font color='green'>用户名可用</font>";
            }
        }
    }
}
